<!DOCTYPE html>
<html lang="zh_CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>test 各种临时测试</title>
  </head>
  <style></style>
  <body></body>
  <script>
    // var words = ['one', 'two', 'three', 'four']
    // words.forEach(function (word) {
    //   console.log(word)
    //   if (word === 'two') {
    //     words.shift()
    //   }
    // })
    // console.log(words)

    class User {
      static url = 'cangge.com'
      constructor(name) {
        this.name = name
      }
    }

    console.dir(User)
    console.dir(new User('anyun'))

    function showPrimes(n) {
      for (let i = 2; i < n; i++) {
        if (!isPrime(i)) continue
        console.log(i) // 一个素数
      }
    }

    function isPrime(n) {
      for (let i = 2; i < n; i++) {
        if (n % i == 0) return false
      }
      return true
    }
    showPrimes(10)
    console.log('\ud835\udcb3')

    let user = {
      firstName: 'John',
      sayHi() {
        alert(`Hello, ${this.firstName}!`)
      },
    }

    let sayHi = user.sayHi.bind(user) // (*)
    // 可以在没有对象（译注：与对象分离）的情况下运行它
    // sayHi() // Hello, John!
    setTimeout(sayHi, 1000) // Hello, John!
    // 即使 user 的值在不到 1 秒内发生了改变
    // sayHi 还是会使用预先绑定（pre-bound）的值
    user = {
      sayHi() {
        alert('Another user in setTimeout!')
      },
    }
  </script>
</html>
